package com.tangsm.api.demo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Service
public class RedisConsumer {

    @Autowired
    public RedisTemplate redisTemplate;
 
    @PostConstruct
    public void init() {
        processOrderImport();
    }
 
    /**
     * 处理订单导入
     */
    private void processOrderImport() {
        ExecutorService executorService = Executors.newCachedThreadPool();
        executorService.execute(() -> {
            while (true) {
//                Object object = redisTemplate.opsForList().rightPop("Test1", 1, TimeUnit.SECONDS);
//                if (null == object) {
//                    continue;
//                }
//                String msg = JSON.toJSONString(object);
//                System.out.println("redis消费者接收数据：" + msg);
            }
        });
    }
 
}